import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { CartService } from '../cart.service';
import { Location } from '@angular/common';
import * as Parse from "parse"
@Component({
  selector: 'app-page-pay',
  templateUrl: './page-pay.component.html',
  styleUrls: ['./page-pay.component.scss']
})
export class PagePayComponent {
  
  currentDate: Date = new Date();
  public alertButtons = ['OK'];
  item:any={}
  CartList:any = []
  constructor(
        private route:ActivatedRoute,
        private router:Router,
    private location :Location,
    private cartServ:CartService
        ){

      this.CartList = this.cartServ.CartList

       /**
     * Angular的ActivatedRoute服务，实现参数解析
     */
    this.route.queryParams.subscribe(async params=>{
        console.log(params)
        let id = params["id"]
        let query = new Parse.Query("goods")
        this.item= await query.get(id)
      })
  
    }

  pay(){
    let GoodsOrder = Parse.Object.extend("goodsorder")
    let order1 = new GoodsOrder();
    let user = Parse.User.current();
    order1.set("goods",this.item.toPointer());
    order1.set("price",100);
    order1.set("isPay",true);
    order1.set("buyer",user?.toPointer());
    order1.save();
    this.goBack()
  }
  
  goBack(){
        this.location.back();
      }
    // goMy(){
    //   this.router.navigate(["../intelligent-shopping/my"])
    // }
    
}
